
var app = new Vue({
    el: '#app',
    data: {
        queryInfo:{
            city: '',
            level: '',
            page: 1,
            pageSize: 10,
            totalNum: 0
        },
        //搜索
        classify: [
            {id: 0,name: '无雾'},
            {id: 1,name: '轻雾'},
            {id: 2,name: '浓雾'}
        ],
        //展示
        tableData: [],
        tableData_temp: []
    },
    created() {
        this.getFogLevel();
    },
    methods:{
        getFogLevel(){
            console.log("我执行发送了！")
            this.$http.get('/admin/FogLevelAll',{}).then(res => {
                console.log(res)
                $("div[id*='left_y']").hide();
                $("#" + res.body.left).show();
                $("#" + res.body.show_left).attr("style", "background: #293038;");
                $("#"+res.body.top).attr("style","background: #008fbf;");
                $(".top_admin .list-group").hide();
                this.tableData = res.body.FogLevel;
                this.tableData_temp = res.body.FogLevel;
                this.queryInfo.totalNum = res.body.FogLevel.length;
                this.handleCurrentChange(1);
            });
        },
        handleSizeChange(size){
            this.queryInfo.pageSize = size;
            this.handleCurrentChange(this.queryInfo.page);
        },
        handleCurrentChange(current){
            this.queryInfo.page = current;
            this.currentChangePage(this.tableData_temp,current)
        },
        //分页方法（重点）
        currentChangePage(list,currentPage) {
            let from = (currentPage - 1) * this.queryInfo.pageSize;
            let to = currentPage * this.queryInfo.pageSize;
            this.tempList = [];
            for (; from < to; from++) {
                if (list[from]) {
                    this.tempList.push(list[from]);
                }
            }
            this.tableData = this.tempList;
        },
        searchFogLevel(){
            const params = {
                city: this.queryInfo.city,
                type: this.queryInfo.level
            };
            if (params.city==="" && params.type!==""){
                params.city="no";
            }else if (params.type==="" && params.city!==""){
                params.type="no";
            }else if (params.city==="" && params.type===""){
                this.getFogLevel();
                return false;
            }
            console.log(params)
            this.$http.post('/admin/FogLevelSearch',params,{emulateJSON:true}).then(res => {
                this.tableData = res.body.FogLevel;
                this.tableData_temp = res.body.FogLevel;
                this.queryInfo.totalNum = res.body.FogLevel.length;
                this.handleCurrentChange(1);
            });
        },
        addFogLevel(){
            location.href = "/admin/addFog.html";
        },
        updateFogLevel(id){
            //sessionStorage 是会话存储，关闭浏览器就没了
            sessionStorage["Fogid"]=id;
            location.href = "/admin/updateFog.html";
        },
        deleteFogLevel(id){
            const params = {
                id: id,
            };
            this.$http.post('/admin/FogLevelDelete',params,{emulateJSON:true}).then(res => {
                layer.msg('操作成功!', {
                    time: 2000
                });
                this.getFogLevel();
            });
        },
    }
})